package ${codeModel.packageName};

<#list importList?keys as key>
import ${importList[key]};
</#list>	

/**
 * @description ${tableClassModel.tableMemo}
 * @author ${dataSource.author}
 * @date ${time}
 */
@Controller
@RequestMapping(value = "admin/${tableClassModel.classVariableName}")
public class ${ClassName} {

	@Autowired
	private ${tableClassModel.className}Dao ${tableClassModel.classVariableName}Dao;
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="${tableClassModel.className}_BEV";
	
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value =  "/showList")
	public @ResponseBody AjaxResult showList(${tableClassModel.className} ${tableClassModel.classVariableName}, PaginationVO pageVo) {
		if (pageVo == null) {
			pageVo = new PaginationVO();
		}
		List<${tableClassModel.className}> dataList = ${tableClassModel.classVariableName}Dao.selectInPage(${tableClassModel.classVariableName}, pageVo);
		AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
				${tableClassModel.classVariableName}Dao.selectTotalRecord(${tableClassModel.classVariableName}));
		return result;
	}
   	
	/**
	 * 新增
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  "/add${tableClassModel.className}")
	public @ResponseBody AjaxResult add${tableClassModel.className}(${tableClassModel.className} ${tableClassModel.classVariableName}) {
	    SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		${tableClassModel.classVariableName}.set${tableClassModel.primaryKey.property?cap_first}(UUIDUtil.getRandomID());
		${tableClassModel.classVariableName}.setCreateBy(user.getSuName());
		${tableClassModel.classVariableName}.setUpdateBy(user.getSuName());
	 	int i=${tableClassModel.classVariableName}Dao.insert(${tableClassModel.classVariableName});
	 	if(i > 0){
	 		return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "${tableClassModel.tableMemo}");
	 	}else {
			throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
		}
	}
	
	
	
	
	
	/**
	 * 修改
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value =  "/modify${tableClassModel.className}")
	public @ResponseBody AjaxResult modify${tableClassModel.className}(${tableClassModel.className} new${tableClassModel.className}) {
	   	${tableClassModel.className} old${tableClassModel.className} = WebUtil.getSessionAttribute(BEV);
		int i = 0;
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(old${tableClassModel.className}, new${tableClassModel.className})) {
				i = MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(old${tableClassModel.className}, new${tableClassModel.className});
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, new${tableClassModel.className});
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("${tableClassModel.primaryKey.property}", old${tableClassModel.className}.get${tableClassModel.primaryKey.property?cap_first}());
			${tableClassModel.classVariableName}Dao.updateByMap(modifyMap);
		}
		i = MatrixConstance.DML_SUCCESSS;
		WebUtil.removeSessionAttribute(BEV);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.UPDATE_SUCCES, "${tableClassModel.tableMemo}");
		} else {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL);
		}
	}
	
	
	
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value =  "/editForm")
	public String editForm(${tableClassModel.primaryKey.classType} id) {
		${tableClassModel.className} ${tableClassModel.classVariableName};
		if (id != null) {
			${tableClassModel.classVariableName} = ${tableClassModel.classVariableName}Dao.selectById(id);
			WebUtil.getRequest().setAttribute("obj", ${tableClassModel.classVariableName});
			WebUtil.setSessionAttribute(BEV, ${tableClassModel.classVariableName});
		}
		return "admin/${tableClassModel.className}-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		List<String> ids = StringUtils.strToCollToString(keys, ",");
		int i =  ${tableClassModel.classVariableName}Dao.deleteByIds(ids);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
		} else {
			throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
		}
	}
  
}